from tkinter import *
import random
import math
root = Tk()
startSteps = 1
def draw(x, y, width, height, xMovement, yMovement, steps, canvas):
    canvas.create_rectangle(x, y, x + width, y + height, width = 3)
    if steps >= 0:
        newSize = 100 * (steps / startSteps)  + 5
        newX = x + (width - newSize) // 2
        newY = y + (height - newSize) // 2
        newX = newX - ((x - newX) // (steps + 2)) * xMovement
        newY = newY - ((y - newY) // (steps + 2)) * yMovement
        draw(newX, newY, newSize, newSize, xMovement, yMovement, \
            steps - 1, canvas)

cv = Canvas(root, width =830, height = 900, bg = 'white')
x = 15
y = 10
directions = [-1,0,1]
while x < 600:
    while y < 820:
        startSteps = 3 + math.ceil(random.random() * 3 )
        xDirection = directions[math.floor(random.random() * 3)]
        yDirection = directions[math.floor(random.random() * 3)]
        draw(x, y, 100, 100, xDirection, yDirection, startSteps - 1,\
             canvas=cv)
        y += 100
    y = 10
    x += 100
cv.pack()
root.mainloop()












